#include <bits/stdc++.h>
using namespace std;
int t,y,m,d,s;
bool isLeap(int x){
    return x%4==0 && x%100!=0 || x%400==0;
}
int main(void){
    int ms[2][13]={
        {0,31,28,31,30,31,30,31,31,30,31,30,31},
        {0,31,29,31,30,31,30,31,31,30,31,30,31}   
    };
    scanf("%d",&t);
    while(t--){
        scanf("%d-%d-%d %d",&y,&m,&d,&s);
        int dd=s/86400;
        d+=dd;
        //printf("%d\n",ms[isLeap(y)][m]);
        while(d>ms[isLeap(y)][m]){
            d-=ms[isLeap(y)][m];
            if(m==12){
                m=0;
                y++;
            }
            m++;
        }
        printf("%d-%02d-%02d\n",y,m,d);
    }
    return 0;
}